package team.niit.service.impl;

import team.niit.dao.NotificationDAO;
import team.niit.dao.impl.NotificationDAOImpl;
import team.niit.entity.NotificationEntity;
import team.niit.service.NotificationService;

import java.util.List;

/**
 * @Author: HAPPY
 * @Project_name: JSF
 * @Package_name: team.niit.service.impl
 * @Date: 2021/10/26 20:01
 */
public class NotificationServiceImpl implements NotificationService {

    private NotificationDAO notificationDAO = new NotificationDAOImpl();

    @Override
    public NotificationEntity publishNotification(NotificationEntity notificationEntity) {

        notificationDAO.insertNotification(notificationEntity);

        return notificationEntity;
    }

    @Override
    public NotificationEntity modifyNotification(NotificationEntity notificationEntity) {
        notificationDAO.updateNotification(notificationEntity);
        return notificationEntity;
    }

    @Override
    public NotificationEntity queryNotificationById(int id) {

        List<NotificationEntity> list = notificationDAO.queryNotificationById(id);

        NotificationEntity notificationEntity = new NotificationEntity();

        notificationEntity.setTime(list.get(0).getTime());
        notificationEntity.setTitle(list.get(0).getTitle());
        notificationEntity.setContent(list.get(0).getContent());
        notificationEntity.setMajor(list.get(0).getMajor());

        return notificationEntity;
    }

    @Override
    public List<NotificationEntity> queryAll() {

        List<NotificationEntity> list = notificationDAO.queryAll();

        return list;
    }

    @Override
    public List<NotificationEntity> queryAllByMajor(String major) {

        List<NotificationEntity> list = notificationDAO.queryAllByMajor(major);

        return list;
    }

    @Override
    public boolean deleteNotificationById(int id) {

        boolean b = notificationDAO.deleteNotificationById(id);

        return b;
    }

    @Override
    public List<NotificationEntity> queryNotificationByPageNum(int pageNum) {
        List<NotificationEntity> list = notificationDAO.queryByPageNum(pageNum);
        return list;
    }

    @Override
    public long countNotificationPageNum() {

        long l = notificationDAO.countPageNum();

        return l;
    }

    @Override
    public long countAllNotificationNum() {
        long l = notificationDAO.countAllNum();
        return l;
    }

    @Override
    public long countSavedNotificationNum() {
        long l = notificationDAO.countAllSavedNum();
        return l;
    }

    @Override
    public List<NotificationEntity> querySavedNotificationByPageNum(int pageNum) {
        List<NotificationEntity> list = notificationDAO.querySavedByPageNum(pageNum);
        return list;
    }

    @Override
    public long countSavedNotificationPageNum() {
        long l = notificationDAO.countSavedPageNum();
        return l;
    }

    @Override
    public NotificationEntity querySavedNotificationById(int id) {
        List<NotificationEntity> list = notificationDAO.querySavedNotificationById(id);

        NotificationEntity notificationEntity = new NotificationEntity();

        notificationEntity.setTime(list.get(0).getTime());
        notificationEntity.setTitle(list.get(0).getTitle());
        notificationEntity.setContent(list.get(0).getContent());
        notificationEntity.setMajor(list.get(0).getMajor());

        return notificationEntity;
    }
}
